﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BlondeHeaven.BLL.Interface;
using BlondeHeaven.Model.Model;
using BlondeHeaven.UI.Models.Commodity;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace BlondeHeaven.UI.Controllers
{
    public class CommodityController : Controller
    {

        private IBllCommodityService<Commodity> _db;

        public CommodityController(IBllCommodityService<Commodity> db)
        {
            _db = db;
        }
        // GET: CommodityController
        public ActionResult Index(int Id)
        {
            var com = _db.GetAllCommodity(Id);
            List<CommodityViewModel> ViewModel = new List<CommodityViewModel>();
            foreach (var item in com)
            {
                var commodityViewModel = new CommodityViewModel();
                commodityViewModel.Id = item.Id;
                commodityViewModel.Name = item.Name;
                commodityViewModel.Photo = item.Photo;
                commodityViewModel.Price = item.Price;
                commodityViewModel.CreateCommodity = item.CreateCommodity;
                ViewModel.Add(commodityViewModel);
            }
            return View(ViewModel);
        }

        // GET: CommodityController/Details/5
        public ActionResult Details(int id)
        {
            return View();
        }

        // GET: CommodityController/Create
        public ActionResult Create()
        {
            return View();
        }

        // POST: CommodityController/Create
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create(IFormCollection collection)
        {
            try
            {
                return RedirectToAction(nameof(Index));
            }
            catch
            {
                return View();
            }
        }

        // GET: CommodityController/Edit/5
        public ActionResult Edit(int id)
        {
            return View();
        }

        // POST: CommodityController/Edit/5
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit(int id, IFormCollection collection)
        {
            try
            {
                return RedirectToAction(nameof(Index));
            }
            catch
            {
                return View();
            }
        }

        // GET: CommodityController/Delete/5
        public ActionResult Delete(int id)
        {
            return View();
        }

        // POST: CommodityController/Delete/5
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Delete(int id, IFormCollection collection)
        {
            try
            {
                return RedirectToAction(nameof(Index));
            }
            catch
            {
                return View();
            }
        }
    }
}
